package com.zytlifeservice.controller.find;

import com.zytlifeservice.domain.Result;
import com.zytlifeservice.domain.find.FinacialServiceBean;
import com.zytlifeservice.service.find.FinacialService;
import com.zytlifeservice.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 金融服务控制类
 * Created by Administrator on 2017/6/2.
 */
@RestController
@RequestMapping(value = "finacial")
public class FinacialServiceController {
    @Autowired
    private FinacialService finacialService;//金融服务业务对象

    //信用卡申请/贷款申请/金融其他服务
    @RequestMapping(value = "/askForService")
    public Result askForService(String type) {
        if (type.equals("信用卡申请")) {
            System.out.println("3");
            List<FinacialServiceBean> finacialServiceList = finacialService.finacialServiceAll("3");
            if (null != finacialServiceList && finacialServiceList.size() > 0) {
                return ResultUtil.success(finacialServiceList, "成功");
            } else {
                return ResultUtil.error(-1, "未获取到数据");
            }
        } else if (type.equals("1")) {
            System.out.println("进入贷款申请服务方法");
            List<FinacialServiceBean> finacialServiceList = finacialService.finacialServiceAll("1");
            List<FinacialServiceBean> finacialServiceLists = finacialService.finacialServiceAll("2");
            List<FinacialServiceBean> finalList = new ArrayList<>();
            if (null != finacialServiceList && finacialServiceList.size() > 0) {//有数据则遍历校园贷款
                for (FinacialServiceBean finacialServices : finacialServiceList) {
                    finalList.add(finacialServices);
                }
            }
            if (null != finacialServiceLists && finacialServiceLists.size() > 0) {//有数据则遍历信用贷款
                for (FinacialServiceBean finacialServices : finacialServiceLists) {
                    finalList.add(finacialServices);
                }
            }
            if (null != finalList && finalList.size() > 0) {//集合数据之后返回
                return ResultUtil.success(finalList, "成功");
            } else {
                return ResultUtil.error(-1, "未获取到服务数据");
            }
        } else {
            System.out.println("进入金融其他服务方法");
            List<FinacialServiceBean> finacialServiceList = finacialService.findFinacialByServiceAll();
            if (null != finacialServiceList && finacialServiceList.size() > 0) {
                return ResultUtil.success(finacialServiceList, "成功");
            } else {
                return ResultUtil.error(-1, "未获取到服务数据");
            }
        }
    }

}
